package com.etc;

import com.etc.services.AService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestMain {
    public static void main(String[] args) {


        System.out.println("====================");

        // {name: tom, age:10}

        Student stu1 = new Student();

        stu1.setName("tom");
        stu1.setAge("10");

        System.out.println(stu1.getName() + "@" + stu1.getAge());


        Dog d = new Dog();
        d.setName("小白");
        d.weishi();

        // 多态：
        Pet p1 = new Dog();
        p1.setName("小黑");
        p1.weishi();
        ((Dog) p1).wangwang();

        // 只要出现类型的时候就可以多态
        stu1.setPet(p1);
        stu1.weishi();

        // IOC

        Student stu2 = new Student();

        // DI
        stu2.setName("jeery");
        stu2.setAge("10");

        Cat c = new Cat();

        c.setName("大脸");

        stu2.setPet(c);
        stu2.weishi();
        System.out.println("=================");

        // 容器实例化
        ApplicationContext context = new ClassPathXmlApplicationContext("springContext.xml");

        // 根据 name或id获取bean
        Object o = context.getBean("stu1");
        // 根据类型获取 bean
        Student stu3 = context.getBean(Student.class);
        stu3.weishi();

        System.out.println("=================");
        AService a = context.getBean(AService.class);
//        System.out.println(a);

        a.add();

        AService b = context.getBean(AService.class);
        System.out.println(b);
        System.out.println(a == b);

    }
}
